import pika
import time
#
connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))
channel =connection.channel()
# queue_declare创建队列是幂等的
channel.queue_declare(queue="Hi",durable=True)
channel.basic_qos(prefetch_count=1) # fanout广播模式
#回调函数
def callback(ch,method,properties,body):
    print("接收了:",body)
    time.sleep(5)
    ch.basic_ack(delivery_tag=method.delivery_tag)

channel.basic_consume(
    queue="Hi",
    on_message_callback=callback,
    auto_ack=False # true的话. 消息没有处理完, 也会删除消息 false 需要手动处理
)
channel.start_consuming()